home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’93 / Mystery Science Mac / INIT sources / Utils.c < prev    next >
C/C++ Source or Header  |  1993-09-01  |  1KB  |  59 lines

  1. #include "MacHeaders7"
  2. #include "Utils.h"
  3. #include "MSM.h"
  4.  
  5. /* FlushCache flushes the 680x0 instruction cache in a compatible way across all CPUs. */
  6.  
  7. void FlushCache(void) {
  8.     if (CPUFlag < 2) return;
  9.     asm 68020 {
  10.         movem.l    d0/d1/a0,-(a7)
  11.         move.w    #0xA098,d0
  12.         GetTrapAddress    NEWOS
  13.         move.l    a0,a1
  14.         move.w    #0xA89F,d0
  15.         GetTrapAddress    NEWTOOL
  16.         cmp.l    a0,a1
  17.         beq.s    @direct
  18.         moveq    #1,d0
  19.         dc.w    0xA098    ; _HWPriv
  20.         goto    restore
  21. direct:    movec    cacr,d1
  22.         addq.w    #8,d1
  23.         movec    d1,cacr
  24. restore:movem.l    (a7)+,d0/d1/a0
  25.     };
  26. }
  27.  
  28.  
  29. /* real address converts a Think C code resource-based jump table entry
  30.    into an actual address. */
  31.  
  32. void *real_address(void *jump_table_entry) {
  33.     asm {
  34.         move.l    jump_table_entry,a0
  35.         cmpi.w    #0x6000,(a0)
  36.         bne.s    @fine
  37.         addq    #2,a0
  38.         add.w    (a0),a0
  39.     fine:
  40.         move.l    a0,d0
  41.         StripAddress
  42.     };
  43. }
  44.  
  45. // jbRelString is an interface to the RelString trap.  It returns zero
  46. // if the strings are equal, 1 if s1 is greater that s2, -1 if neither.
  47.  
  48. short jbRelString(register void *first, register void *second) {
  49.     asm {
  50.         moveq    #0,d0
  51.         move.l    first,a0
  52.         move.l    second,a1
  53.         move.b    (a0)+,d0
  54.         swap    d0
  55.         move.b    (a1)+,d0
  56.         RelString
  57. out:;
  58.     }
  59. }